--
-- @Author:      qinxugao
-- @DateTime:    2018-03-30 23:05:48
-- @Description: 消息的派发

local skynet = require "skynet"
local log = require "Log"


local Message = class("Message")

---------------------------------------------------------
-- Private
---------------------------------------------------------
function Message:ctor(svrName)
	--print("_#svrName#####"..svrName)
	self.svrName = svrName or ""
	self.tbSelfMsg = {} --本服务要监听的消息
end

--注册本服务里的消息
function Message:registerSelf(msgName,callback)
	self.tbSelfMsg[msgName] = callback
end

--消息派发
function Message:dispatchMessage( session, source, cmd, ... )
	local ok, res
	local func = self.tbSelfMsg[cmd] -- gate是否有handler
	if not func then 
		--log.error("####### cmd "..cmd .." not found at robot "..self.svrName)
		print("###########niuniu dispatchMessage not found message func ",cmd)
		return
	end
	--skynet.retpack(xx_pcall(func, ...))
	skynet.retpack(xx_pcall(func, ...))
end

function Message:dispatch()
	return handler(self,self.dispatchMessage)
end

return Message